
var api = require('../../utils/api.js');
var app = getApp();


Page({

    /**
     * 页面的初始数据
     */
    data: {
        status: -1,
        lists: []
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onLoad() {
        this.getmyorder();
    },
    seelist(ret){
        console.log(ret);
        var index=ret.currentTarget.dataset.i;
        this.setData({
            status:index,
            lists:[]
        })
        this.getmyorder();
    },

    getmyorder(){
        var that=this;
        var status=this.data.status;
        api.post({
            url: 'worker/getmyorder',
            data: {status:status},
            success: data => {
                that.setData({
                    lists:data.data
                })
            
            }
        })


    },
    // 订单完成
    payorder(ret){
        console.log(ret);
        var id=ret.currentTarget.dataset.id;
        var that=this;

        wx.showModal({
          title: '提示',
          content: '确认订单已经完成？',
          complete: (res) => {
            if (res.confirm) {
                api.post({
                    url: 'worker/ordersuccess',
                    data: {id:id},
                    success: data => {
                        that.getmyorder();
                    }
                })
            }
          }
        })

  

    },


    suoding(ret){
        console.log(ret);
        var id=ret.currentTarget.dataset.id;
        var that=this;

        wx.showModal({
          title: '提示',
          content: '确认订单已经完成？',
          complete: (res) => {
            if (res.confirm) {
                api.post({
                    url: 'worker/suoding',
                    data: {id:id},
                    success: data => {
                        that.getmyorder();
                    }
                })
            }
          }
        })
    },

    quxiao(ret){
        var id=ret.currentTarget.dataset.id;
        var that=this;

        wx.showModal({
            title: '退款',
            content: '确认要进行退款',
            complete: (res) => {
                if (res.confirm) {
                    api.post({
                        url: 'order/doRefund',
                        data: {oid:id,types:0},
                        success: data => {
                            console.log(data);
                            that.getmyorder();
                        }
                    })
                }
            }
        })

    },
    seeorderbyid(ret) {
        console.log(ret);
        var id = ret.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/work/orderinfo?id=' + id
        })
    },
})